/*
 * GameFrame.java
 * Team qq 2011
 */
package com.google.code.timetrail.gui;

import java.awt.Color;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.CardLayout;

import javax.swing.DefaultListModel;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JList;
import javax.swing.AbstractListModel;
import javax.swing.UIManager;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.List;

import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.AncestorListener;
import javax.swing.event.AncestorEvent;

import com.google.code.timetrail.backend.*;
import javax.swing.JTable;
import javax.swing.SpringLayout;
import java.awt.BorderLayout;
import javax.swing.BoxLayout;
import javax.swing.SwingConstants;

public class GameFrame extends JFrame implements DocumentListener {


	/**
	 * acts as the gui for the game
	 * @author Apurv 
	 * @version 1.01
	 * added inventory instantiation to the frame
	 */
	private static final long serialVersionUID = 1L;
	private JPanel contentPane;
	private JLabel gameTitleLabel;
	private JLabel enterNameLabel;
	private JTextField enterNameTextField;
	private JLabel addMembersLabel;
	private JButton addButton;
	private JList professionList;
	private JLabel professionTextField;
	private JList additionalMembersList;
	private JButton nextButton;
	private JLabel rationsLabel;
	private JLabel paceLabel;
	private JList rationsList;
	private JList paceList;
	private JButton nextButton2;
	private JButton backButton;
	private JFrame frame;
	private DefaultListModel model;
	protected int addButtonCount;
	private List<String> additionalPlayers;
	private String selectedProfession;
	private travelSpeed pace;
	private consumptionRate rations;
	private Control gameControl;
	private Inventory playerInventory;
	private JLabel quantityLabel;
	private JLabel itemNameLabel;
	private JLabel priceAndWeightLabel;
	private JPanel storePanel;
	private JLabel oxenLabel;
	private JLabel foodLabel;
	private JLabel clothingLabel;
	private JLabel ammunitionLabel;
	private JLabel wagonWheelLabel;
	private JLabel wagonAxleLabel;
	private JLabel wagonTongueLabel;
	private JLabel oxenPriceWeightLabel;
	private JLabel foodPriceWeightLabel;
	private JLabel clothingPriceWeightLabel;
	private JLabel ammunitionPriceWeightLabel;
	private JLabel wagonWheelPriceWeightLabel;
	private JLabel wagonAxlePriceWeightLabel;
	private JLabel wagonTonguePriceWeightLabel;
	private JTextField foodTextField;
	private JTextField clothingTextField;
	private JTextField ammunitionTextField;
	private JTextField wagonWheelTextField;
	private JTextField wagonAxleTextField;
	private JTextField wagonTongueTextField;
	private JTextField oxenTextField;
	private JButton nextButton3;
	private JButton backButton2;
	private JLabel moneyLabel;
	private JLabel totalCostLabel;
	private JLabel totalWeightLabel;
	private JLabel storeLabel;
	private final static Color ERROR_COLOR=Color.pink;
	private final static Color GOOD_COLOR=Color.white;
	private Store store;
	private int storeTotal, weightTotal;
	private int[] storeInputs;
	private boolean oxenTextFieldValidity = true;
	private boolean wagonTongueTextFieldValidity = true;
	private boolean wagonAxleTextFieldValidity = true;
	private boolean wagonWheelTextFieldValidity = true;
	private boolean clothingTextFieldValidity = true;
	private boolean foodTextFieldValidity = true;
	private boolean ammunitionTextFieldValidity = true;
	

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {

		try{
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch(Exception e){
			System.err.println("Unable to use native look and feel");
		}

		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					GameFrame frame = new GameFrame();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	public boolean checkTextFields(){
		if(canBuyFromStore()){
			if(checkDataValidity(oxenTextField.getText())){
				oxenTextField.setBackground(GOOD_COLOR);
			}
			if(checkDataValidity(wagonTongueTextField.getText())){
				wagonTongueTextField.setBackground(GOOD_COLOR);
			}
			if(checkDataValidity(wagonAxleTextField.getText())){
				wagonAxleTextField.setBackground(GOOD_COLOR);
			}
			if(checkDataValidity(wagonWheelTextField.getText())){
				wagonWheelTextField.setBackground(GOOD_COLOR);
			}
			if(checkDataValidity(clothingTextField.getText())){
				clothingTextField.setBackground(GOOD_COLOR);
			}
			if(checkDataValidity(foodTextField.getText())){
				foodTextField.setBackground(GOOD_COLOR);
			}
			if(checkDataValidity(ammunitionTextField.getText())){
				ammunitionTextField.setBackground(GOOD_COLOR);
			}
			totalWeightLabel.setText("Total Weight: " + weightTotal);
			totalCostLabel.setText("Total Cost: " + storeTotal);
		}
		return oxenTextFieldValidity && wagonTongueTextFieldValidity && wagonAxleTextFieldValidity && wagonWheelTextFieldValidity && clothingTextFieldValidity && foodTextFieldValidity && ammunitionTextFieldValidity;
	}
	/**
	 * Checks if the data is a valid integer
	 * @param content
	 * @return
	 */
	public boolean checkDataValidity(String content)
	{
		try
		{
			int val=Integer.parseInt(content);
			return val >= 0;
		}
		catch(NumberFormatException e)
		{
			return false;
		}
	}
	
	/**
	 * Calculates the total money left for the user and the total weight of the spaceship and enables/disables the next button
	 */
	public boolean canBuyFromStore()
	{

		//checks against total weight of spaceship and total money the user has and based on that it enables/disables the next button
		//recalculates current money user has and makes change to the necessary moneyLabel
		//recalculates total weight of spaceship and total cost based on recieved input
		
		int currentMoney = gameControl.getInv().getMoney().getCurrentAmount();
		
		int oxenValue = gameControl.getInv().getEngines().getValue()*storeInputs[0];
		int foodValue = gameControl.getInv().getFood().getValue()*storeInputs[1];
		int clothingValue = gameControl.getInv().getTimeSuits().getValue()*storeInputs[2];
		int ammunitionValue = gameControl.getInv().getTimeBulletBills().getValue()*storeInputs[3];
		int wagonWheelValue = gameControl.getInv().getfCapacitors().getValue()*storeInputs[4]; 
		int wagonAxleValue = gameControl.getInv().getHullParts().getValue()*storeInputs[5];
		int wagonTongueValue = gameControl.getInv().getFuelCells().getValue()*storeInputs[6];
		
		storeTotal = oxenValue + foodValue + clothingValue + ammunitionValue + wagonWheelValue + wagonAxleValue + wagonTongueValue;
		
		int currentWeight = gameControl.getInv().getInvWeight();
		int maxCapacity = gameControl.getInv().getCapacity();
		int freeCapacity = maxCapacity - currentWeight;
		
		int foodWeight = gameControl.getInv().getFood().getWeight()*storeInputs[1];
		int clothingWeight = gameControl.getInv().getTimeSuits().getWeight()*storeInputs[2];
		int ammunitionWeight = gameControl.getInv().getTimeBulletBills().getWeight()*storeInputs[3];
		int wagonWheelWeight = gameControl.getInv().getfCapacitors().getWeight()*storeInputs[4]; 
		int wagonAxleWeight = gameControl.getInv().getHullParts().getWeight()*storeInputs[5];
		int wagonTongueWeight = gameControl.getInv().getFuelCells().getWeight()*storeInputs[6];
		
		weightTotal = foodWeight + clothingWeight + ammunitionWeight + wagonWheelWeight + wagonAxleWeight + wagonTongueWeight;
		
		int remainingCapacity = freeCapacity - weightTotal;
		
		return (currentMoney >= storeTotal)&&(remainingCapacity >= 0);
	}
	/**
	 * Create the frame.
	 */
	public GameFrame() {
		gameControl = new Control();
		store = new Store(gameControl);
		additionalPlayers = new ArrayList<String>();
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 600, 500);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(new CardLayout(0, 0));
		
		JPanel startupPanel = new JPanel();
		contentPane.add(startupPanel, "name_1317839433132283000");
		startupPanel.setLayout(null);
		
		gameTitleLabel = new JLabel("Time Trail\n");
		gameTitleLabel.setBounds(295, 0, 67, 32);
		startupPanel.add(gameTitleLabel);
		
		enterNameLabel = new JLabel("Enter Name:");
		enterNameLabel.setBounds(200, 66, 76, 16);
		startupPanel.add(enterNameLabel);
		
		enterNameTextField = new JTextField();
		enterNameTextField.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				
			}
		});
		enterNameTextField.setBounds(295, 60, 134, 28);
		enterNameTextField.setText("player1");
		startupPanel.add(enterNameTextField);
		enterNameTextField.setColumns(10);
		
		addMembersLabel = new JLabel("Enter Name of additional Party members:");
		addMembersLabel.setBounds(19, 101, 257, 16);
		startupPanel.add(addMembersLabel);
		
		final DefaultListModel model = new DefaultListModel();
		additionalMembersList = new JList(model);
		additionalMembersList.setBounds(295, 133, 134, 115);
		additionalMembersList.setVisibleRowCount(4);
		startupPanel.add(additionalMembersList);
		
		addButton = new JButton("Add");
		addButton.addActionListener(new ActionListener() {
			
			
			public void actionPerformed(ActionEvent e) {
				if(addButtonCount<4){
				String s = JOptionPane.showInputDialog(
				                    frame,
				                    "Enter Name of additional Party member",
				                    "Name"
				                    );
				
				if ((s != null) && (s.length() > 0)) {
					int pos = additionalMembersList.getModel().getSize();
					model.add(pos,s);
					additionalPlayers.add(s);
					addButtonCount++;
				    return;
				}
				}

				//If you're here, the return value was null/empty.
				//setLabel("Come on, finish the sentence!");
			}
		});
		addButton.setBounds(295, 100, 75, 29);
		startupPanel.add(addButton);
		
		professionList = new JList();
		professionList.addListSelectionListener(new ListSelectionListener() {
			public void valueChanged(ListSelectionEvent e) {
				if(professionList.getSelectedIndex() == 0){
					selectedProfession = "Engineer";
				} else if(professionList.getSelectedIndex() == 1){
					selectedProfession = "Nutritionist";
				} else if(professionList.getSelectedIndex() == 2){
					selectedProfession = "Doctor";
				} else if(professionList.getSelectedIndex() == 3){
					selectedProfession = "Entrepreneur";
				}
			}
		});
		professionList.setModel(new AbstractListModel() {
			String[] values = new String[] {"Engineer", "Nutritionist", "Doctor", "Entrepreneur"};
			public int getSize() {
				return values.length;
			}
			public Object getElementAt(int index) {
				return values[index];
			}
		});
		professionList.setBounds(295, 260, 134, 76);
		professionList.setVisibleRowCount(4);
		startupPanel.add(professionList);
		
		professionTextField = new JLabel("Choose Profession:");
		professionTextField.setBounds(155, 260, 121, 16);
		startupPanel.add(professionTextField);
		
		nextButton = new JButton("Next >");
		nextButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				CardLayout cd = (CardLayout) contentPane.getLayout();
                
                String name = enterNameTextField.getText();
                
                Person player = null;
                if(name.equals("") || name == null || professionList.getSelectedIndex() == -1){
                	JOptionPane.showMessageDialog(frame,
                		    "Please fill in all required information.",
                		    "Some fields were left empty",
                		    JOptionPane.PLAIN_MESSAGE);
                } else {
                	if(selectedProfession.equals("Engineer")){
                		player = new Engineer();
                	} else if(selectedProfession.equals("Nutritionist")){
                		player = new Nutritionist();
                	} else if(selectedProfession.equals("Doctor")){
                		player = new Doctor();
                	} else if(selectedProfession.equals("Entrepreneur")){
                		player = new Entrepreneur();
                	}
                	ArrayList<Person> members = new ArrayList<Person>();
	                	for(int i = 0; i < additionalPlayers.size(); i++){
	                		members.add(new Person(additionalPlayers.get(i)));
	                	}
                	
                	player.setName(name);
                	playerInventory = new Inventory();
                	player.initialBonus(playerInventory);
                	gameControl.setInv(playerInventory);
                	gameControl.setPlayer(player);
                	gameControl.setMembers(members);
                	cd.next(contentPane);
                	//selectedProfession - the String selected profession
                	//name = player name, can't be empty or null
                	//additionalPlayers - array that holds the additional players, null if empty
                	
                }
			}
		});
		nextButton.setBounds(447, 412, 117, 29);
		startupPanel.add(nextButton);
		
		JPanel paceAndRationsPanel = new JPanel();
		contentPane.add(paceAndRationsPanel, "name_1317840867491837000");
		paceAndRationsPanel.setLayout(null);
		
		paceLabel = new JLabel("Select Pace:");
		paceLabel.setBounds(164, 131, 73, 16);
		paceAndRationsPanel.add(paceLabel);
		
		rationsLabel = new JLabel("Select Rations:");
		rationsLabel.setBounds(139, 285, 98, 16);
		paceAndRationsPanel.add(rationsLabel);
		
		rationsList = new JList();
		rationsList.addListSelectionListener(new ListSelectionListener() {
			public void valueChanged(ListSelectionEvent e) {
				if(rationsList.getSelectedIndex() == 0){
					rations = consumptionRate.NONE;
				} else if(rationsList.getSelectedIndex() == 1){
					rations = consumptionRate.BAREBONES;
				} else if(rationsList.getSelectedIndex() == 2){
					rations = consumptionRate.MEAGER;
				} else if(rationsList.getSelectedIndex() == 3){
					rations = consumptionRate.NORMAL;
				} else if(rationsList.getSelectedIndex() == 4){
					rations = consumptionRate.WELLFED;
				}
			}
		});
		rationsList.setModel(new AbstractListModel() {
			String[] values = new String[] {"None ", "bare-bones ", "Meager ", "Normal", "Wellfed "};
			public int getSize() {
				return values.length;
			}
			public Object getElementAt(int index) {
				return values[index];
			}
		});
		rationsList.setBounds(250, 285, 118, 85);
		paceAndRationsPanel.add(rationsList);
		
		paceList = new JList();
		paceList.addListSelectionListener(new ListSelectionListener() {
			public void valueChanged(ListSelectionEvent arg0) {
				if(paceList.getSelectedIndex() == 0){
					pace = travelSpeed.STOPPED;
				} else if(paceList.getSelectedIndex() == 1){
					pace = travelSpeed.MACH;
				} else if(paceList.getSelectedIndex() == 2){
					pace = travelSpeed.WARP;
				} else if(paceList.getSelectedIndex() == 3){
					pace = travelSpeed.LUDICROUS;
				}
			}
		});
		paceList.setModel(new AbstractListModel() {
			String[] values = new String[] {"Stopped", "Mach", "Warp", "Ludacris"};
			public int getSize() {
				return values.length;
			}
			public Object getElementAt(int index) {
				return values[index];
			}
		});
		paceList.setBounds(250, 131, 118, 68);
		paceAndRationsPanel.add(paceList);
		
		nextButton2 = new JButton("Next >");
		nextButton2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(paceList.getSelectedIndex() == -1 || rationsList.getSelectedIndex() == -1){
					JOptionPane.showMessageDialog(frame,
                		    "Please fill in all required information.",
                		    "Some fields were left empty",
                		    JOptionPane.PLAIN_MESSAGE);
				} else {
					
					
					gameControl.setPace(pace);
					gameControl.setRations(rations);
					moneyLabel.setText("Money:" + gameControl.getInv().getMoney().getCurrentAmount());
					/*JOptionPane.showMessageDialog(frame,
                		    "Configuration Complete",
                		   "Configuration Complete",
                		    JOptionPane.PLAIN_MESSAGE);*/
					CardLayout cd = (CardLayout) contentPane.getLayout();
					cd.next(contentPane);
				}
			}
		});
		
		nextButton2.setBounds(447, 412, 117, 29);
		paceAndRationsPanel.add(nextButton2);
		
		backButton = new JButton("< Back");
		backButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				CardLayout cd = (CardLayout) contentPane.getLayout();
                cd.previous(contentPane);
			}
		});
		backButton.setBounds(320, 412, 117, 29);
		paceAndRationsPanel.add(backButton);
		
		storeTotal = 0; 
		weightTotal = 0; 
		storeInputs = new int[7];
		for (int i=0; i<7; i++) {
			storeInputs[i] = 0;
		}
		
		JPanel inventoryPanel = new JPanel();
		contentPane.add(inventoryPanel, "name_1318215791551699000");
		inventoryPanel.setLayout(null);
		
		storePanel = new JPanel();
		storePanel.setBounds(69, 34, 454, 373);
		inventoryPanel.add(storePanel);
		storePanel.setLayout(null);
		
		storeLabel = new JLabel("STORE");
		storeLabel.setBounds(198, 6, 49, 16);
		storePanel.add(storeLabel);
		
		quantityLabel = new JLabel("Quantity");
		quantityLabel.setBounds(341, 50, 54, 16);
		storePanel.add(quantityLabel);
		
		itemNameLabel = new JLabel("Item");
		itemNameLabel.setBounds(39, 50, 28, 16);
		storePanel.add(itemNameLabel);
		
		priceAndWeightLabel = new JLabel("Price / Weight");
		priceAndWeightLabel.setBounds(169, 50, 88, 16);
		storePanel.add(priceAndWeightLabel);
		
		oxenLabel = new JLabel("Oxen");
		oxenLabel.setBounds(39, 82, 61, 16);
		storePanel.add(oxenLabel);
		
		foodLabel = new JLabel("Food");
		foodLabel.setBounds(39, 110, 41, 16);
		storePanel.add(foodLabel);
		
		clothingLabel = new JLabel("Clothing");
		clothingLabel.setBounds(39, 138, 61, 16);
		storePanel.add(clothingLabel);
		
		ammunitionLabel = new JLabel("Ammunition");
		ammunitionLabel.setBounds(39, 166, 88, 16);
		storePanel.add(ammunitionLabel);
		
		wagonWheelLabel = new JLabel("Wagon Wheel");
		wagonWheelLabel.setBounds(39, 194, 88, 16);
		storePanel.add(wagonWheelLabel);
		
		wagonAxleLabel = new JLabel("Wagon Axle");
		wagonAxleLabel.setBounds(39, 222, 78, 16);
		storePanel.add(wagonAxleLabel);
		
		wagonTongueLabel = new JLabel("Wagon Tongue");
		wagonTongueLabel.setBounds(39, 249, 99, 16);
		storePanel.add(wagonTongueLabel);
		
		oxenPriceWeightLabel = new JLabel("$40 / N/A");
		oxenPriceWeightLabel.setBounds(169, 82, 88, 16);
		storePanel.add(oxenPriceWeightLabel);
		
		foodPriceWeightLabel = new JLabel("$1 / 5 lb.");
		foodPriceWeightLabel.setBounds(169, 110, 61, 16);
		storePanel.add(foodPriceWeightLabel);
		
		clothingPriceWeightLabel = new JLabel("$10 / 3 lb.");
		clothingPriceWeightLabel.setBounds(169, 138, 71, 16);
		storePanel.add(clothingPriceWeightLabel);
		
		ammunitionPriceWeightLabel = new JLabel("$2 / 3 lb.");
		ammunitionPriceWeightLabel.setBounds(169, 166, 61, 16);
		storePanel.add(ammunitionPriceWeightLabel);
		
		wagonWheelPriceWeightLabel = new JLabel("$10 / 75 lb.");
		wagonWheelPriceWeightLabel.setBounds(169, 194, 81, 16);
		storePanel.add(wagonWheelPriceWeightLabel);
		
		wagonAxlePriceWeightLabel = new JLabel("$10 / 125 lb.");
		wagonAxlePriceWeightLabel.setBounds(169, 222, 88, 16);
		storePanel.add(wagonAxlePriceWeightLabel);
		
		wagonTonguePriceWeightLabel = new JLabel("$10 / 100 lb.");
		wagonTonguePriceWeightLabel.setBounds(169, 249, 88, 16);
		storePanel.add(wagonTonguePriceWeightLabel);
		
		oxenTextField = new JTextField();
		oxenTextField.setHorizontalAlignment(SwingConstants.CENTER);
		oxenTextField.setText("0");
		/*oxenTextField.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String content=oxenTextField.getText();
				boolean checkValid=checkDataValidity(content);
				if(!checkValid){
					oxenTextField.setBackground(ERROR_COLOR);
					oxenTextFieldValidity = false;
					nextButton3.setEnabled(false);
				}
				else if(Integer.parseInt(oxenTextField.getText()) > gameControl.getInv().getEngines().getMaxAmount()){
					oxenTextField.setBackground(ERROR_COLOR);
					oxenTextFieldValidity = false;
					nextButton3.setEnabled(false);
				}
				else{
					storeInputs[0] = Integer.parseInt(oxenTextField.getText());
					if (canBuyFromStore()) {
						oxenTextFieldValidity = true;
						oxenTextField.setBackground(GOOD_COLOR);
						totalWeightLabel.setText("Total Weight: " + weightTotal);
						totalCostLabel.setText("Total Cost: " + storeTotal);
						if(checkTextFields()){
							nextButton3.setEnabled(true);
							
						}
					} else {
						nextButton3.setEnabled(false);
						oxenTextFieldValidity = false;
						oxenTextField.setBackground(ERROR_COLOR);
					}
					
				}
			}
		});*/
		oxenTextField.setBounds(341, 76, 54, 28);
		storePanel.add(oxenTextField);
		oxenTextField.setColumns(10);
		
		foodTextField = new JTextField();
		/*foodTextField.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String content=foodTextField.getText();
				boolean checkValid=checkDataValidity(content);
				if(!checkValid){
					foodTextField.setBackground(ERROR_COLOR);
					foodTextFieldValidity = false;
					nextButton3.setEnabled(false);
				}
				else if(Integer.parseInt(foodTextField.getText()) > gameControl.getInv().getFood().getMaxAmount()){
					foodTextField.setBackground(ERROR_COLOR);
					foodTextFieldValidity = false;
					nextButton3.setEnabled(false);
				}
				else {
					
					storeInputs[1] = Integer.parseInt(foodTextField.getText());
					if (canBuyFromStore()) {
						foodTextField.setBackground(GOOD_COLOR);
						foodTextFieldValidity = true;
						totalWeightLabel.setText("Total Weight: " + weightTotal);
						totalCostLabel.setText("Total Cost: " + storeTotal);
						if(checkTextFields()){
							nextButton3.setEnabled(true);
							
							
						}
					} else {
						nextButton3.setEnabled(false);
						foodTextFieldValidity = false;
						foodTextField.setBackground(ERROR_COLOR);
					}
				}
			}
		});*/
		foodTextField.setHorizontalAlignment(SwingConstants.CENTER);
		foodTextField.setText("0");
		foodTextField.setBounds(341, 104, 54, 28);
		storePanel.add(foodTextField);
		foodTextField.setColumns(10);
		
		clothingTextField = new JTextField();
		/*clothingTextField.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String content=clothingTextField.getText();
				boolean checkValid=checkDataValidity(content);
				if(!checkValid){
					clothingTextField.setBackground(ERROR_COLOR);
					clothingTextFieldValidity = false;
					nextButton3.setEnabled(false);
				}
				else if(Integer.parseInt(clothingTextField.getText()) > gameControl.getInv().getTimeSuits().getMaxAmount()){
					clothingTextField.setBackground(ERROR_COLOR);
					clothingTextFieldValidity = false;
					nextButton3.setEnabled(false);
					
				}
				else {
					
					storeInputs[2] = Integer.parseInt(clothingTextField.getText());
					if (canBuyFromStore()) {
						clothingTextField.setBackground(GOOD_COLOR);
						clothingTextFieldValidity = true;
						totalWeightLabel.setText("Total Weight: " + weightTotal);
						totalCostLabel.setText("Total Cost: " + storeTotal);
						if(checkTextFields()){
							nextButton3.setEnabled(true);
							
							
						}
					} else {
						nextButton3.setEnabled(false);
						clothingTextFieldValidity = false;
						clothingTextField.setBackground(ERROR_COLOR);
					}
				}
			}
		});*/
		
		clothingTextField.setText("0");
		clothingTextField.setHorizontalAlignment(SwingConstants.CENTER);
		clothingTextField.setBounds(341, 132, 54, 28);
		storePanel.add(clothingTextField);
		clothingTextField.setColumns(10);
		
		ammunitionTextField = new JTextField();
		/*ammunitionTextField.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String content=ammunitionTextField.getText();
				boolean checkValid=checkDataValidity(content);
				if(!checkValid){
					ammunitionTextField.setBackground(ERROR_COLOR);
					ammunitionTextFieldValidity = false;
					nextButton3.setEnabled(false);
					
				}
				else if(Integer.parseInt(ammunitionTextField.getText()) > gameControl.getInv().getTimeBulletBills().getMaxAmount()){
					ammunitionTextField.setBackground(ERROR_COLOR);
					ammunitionTextFieldValidity = false;
					nextButton3.setEnabled(false);
					
				}
				else {
					
					storeInputs[3] = Integer.parseInt(ammunitionTextField.getText());
					if (canBuyFromStore()) {
						ammunitionTextField.setBackground(GOOD_COLOR);
						ammunitionTextFieldValidity = true;
						totalWeightLabel.setText("Total Weight: " + weightTotal);
						totalCostLabel.setText("Total Cost: " + storeTotal);
						if(checkTextFields()){
						nextButton3.setEnabled(true);
						
						
						}
					} else {
						nextButton3.setEnabled(false);
						ammunitionTextFieldValidity = false;
						ammunitionTextField.setBackground(ERROR_COLOR);
					}
				}
			}
		});*/
		ammunitionTextField.setText("0");
		ammunitionTextField.setHorizontalAlignment(SwingConstants.CENTER);
		ammunitionTextField.setBounds(341, 160, 54, 28);
		storePanel.add(ammunitionTextField);
		ammunitionTextField.setColumns(10);
		
		wagonWheelTextField = new JTextField();
		/*wagonWheelTextField.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String content=wagonWheelTextField.getText();
				boolean checkValid=checkDataValidity(content);
				if(!checkValid){
					wagonWheelTextField.setBackground(ERROR_COLOR);
					wagonWheelTextFieldValidity = false;
					nextButton3.setEnabled(false);
				}
				else if(Integer.parseInt(wagonWheelTextField.getText()) > gameControl.getInv().getfCapacitors().getMaxAmount()){
					wagonWheelTextField.setBackground(ERROR_COLOR);
					wagonWheelTextFieldValidity = false;
					nextButton3.setEnabled(false);
					
				}
				else {
					
					storeInputs[4] = Integer.parseInt(wagonWheelTextField.getText());
					if (canBuyFromStore()) {
						wagonWheelTextField.setBackground(GOOD_COLOR);
						wagonWheelTextFieldValidity = true;
						totalWeightLabel.setText("Total Weight: " + weightTotal);
						totalCostLabel.setText("Total Cost: " + storeTotal);
						if(checkTextFields()){
						nextButton3.setEnabled(true);
						
						
						}
					} else {
						nextButton3.setEnabled(false);
						wagonWheelTextFieldValidity = false;
						wagonWheelTextField.setBackground(ERROR_COLOR);
					}
				}
			}
		});*/
		wagonWheelTextField.setText("0");
		wagonWheelTextField.setHorizontalAlignment(SwingConstants.CENTER);
		wagonWheelTextField.setBounds(341, 188, 54, 28);
		storePanel.add(wagonWheelTextField);
		wagonWheelTextField.setColumns(10);
		
		wagonAxleTextField = new JTextField();
		/*wagonAxleTextField.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String content=wagonAxleTextField.getText();
				boolean checkValid=checkDataValidity(content);
				if(!checkValid){
					nextButton3.setEnabled(false);
					wagonAxleTextFieldValidity = false;
					wagonAxleTextField.setBackground(ERROR_COLOR);
				}
				else if(Integer.parseInt(wagonAxleTextField.getText()) > gameControl.getInv().getHullParts().getMaxAmount()){
					wagonAxleTextField.setBackground(ERROR_COLOR);
					wagonAxleTextFieldValidity = false;
					nextButton3.setEnabled(false);
					
				}
				else {
					
					storeInputs[5] = Integer.parseInt(wagonAxleTextField.getText());
					if (canBuyFromStore()) {
						wagonAxleTextField.setBackground(GOOD_COLOR);
						wagonAxleTextFieldValidity = true;
						totalWeightLabel.setText("Total Weight: " + weightTotal);
						totalCostLabel.setText("Total Cost: " + storeTotal);
						if(checkTextFields()){
						nextButton3.setEnabled(true);
						
						
						}
					} else {
						nextButton3.setEnabled(false);
						wagonAxleTextFieldValidity = false;
						wagonAxleTextField.setBackground(ERROR_COLOR);
					}
				}
			}
		});*/
		wagonAxleTextField.setText("0");
		wagonAxleTextField.setHorizontalAlignment(SwingConstants.CENTER);
		wagonAxleTextField.setBounds(341, 216, 54, 28);
		storePanel.add(wagonAxleTextField);
		wagonAxleTextField.setColumns(10);
		
		wagonTongueTextField = new JTextField();
		/*wagonTongueTextField.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String content=wagonTongueTextField.getText();
				boolean checkValid=checkDataValidity(content);
				if(!checkValid){
					nextButton3.setEnabled(false);
					wagonTongueTextFieldValidity = false;
					wagonTongueTextField.setBackground(ERROR_COLOR);
				}
				else if(Integer.parseInt(wagonTongueTextField.getText()) > gameControl.getInv().getFuelCells().getMaxAmount()){
					wagonTongueTextField.setBackground(ERROR_COLOR);
					wagonTongueTextFieldValidity = false;
					nextButton3.setEnabled(false);
				}
				else {
					storeInputs[6] = Integer.parseInt(wagonTongueTextField.getText());
					if (canBuyFromStore()) {
						wagonTongueTextField.setBackground(GOOD_COLOR);
						wagonTongueTextFieldValidity = true;
						totalWeightLabel.setText("Total Weight: " + weightTotal);
						totalCostLabel.setText("Total Cost: " + storeTotal);
						if(checkTextFields()){
						nextButton3.setEnabled(true);
						
						
						}
					} else {
						nextButton3.setEnabled(false);
						wagonTongueTextFieldValidity = false;
						wagonTongueTextField.setBackground(ERROR_COLOR);
					} 
				}
			}
		});*/
		wagonTongueTextField.setHorizontalAlignment(SwingConstants.CENTER);
		wagonTongueTextField.setText("0");
		wagonTongueTextField.setBounds(341, 243, 54, 28);
		storePanel.add(wagonTongueTextField);
		wagonTongueTextField.setColumns(10);
		
		totalWeightLabel = new JLabel("Total Weight: " + weightTotal);
		totalWeightLabel.setBounds(169, 290, 105, 16);
		storePanel.add(totalWeightLabel);
		
		totalCostLabel = new JLabel("Total Cost: " + storeTotal);
		totalCostLabel.setBounds(169, 318, 98, 16);
		storePanel.add(totalCostLabel);
		
		moneyLabel = new JLabel("Money:" + gameControl.getInv().getMoney().getCurrentAmount());
		moneyLabel.setBounds(39, 290, 99, 16);
		storePanel.add(moneyLabel);	
		
		oxenTextField.getDocument().addDocumentListener(this);
		foodTextField.getDocument().addDocumentListener(this);
		clothingTextField.getDocument().addDocumentListener(this);
		ammunitionTextField.getDocument().addDocumentListener(this);
		wagonWheelTextField.getDocument().addDocumentListener(this);
		wagonAxleTextField.getDocument().addDocumentListener(this);
		wagonTongueTextField.getDocument().addDocumentListener(this);
		
		nextButton3 = new JButton("Next >");
		nextButton3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				CardLayout cd = (CardLayout) contentPane.getLayout();
				cd.next(contentPane);
				
				store.setTempEngines(Integer.parseInt(oxenTextField.getText()));
				store.setTempFCapacitors(Integer.parseInt(wagonWheelTextField.getText()));
				store.setTempFood(Integer.parseInt(foodTextField.getText()));
				store.setTempHullParts(Integer.parseInt(wagonAxleTextField.getText()));
				store.setTempFuelCells(Integer.parseInt(wagonTongueTextField.getText()));
				store.setTempTimeSuits(Integer.parseInt(clothingTextField.getText()));
				store.setTempTimeBulletBills(Integer.parseInt(ammunitionTextField.getText()));
				
				//add instances of the inventory items
				if(store.getTempCost() >= 0 && store.getTempWeight() < gameControl.getInv().getCapacity()) {//MAX_CAPACITY
					
					
					store.buyItem(Integer.parseInt(wagonTongueTextField.getText()), gameControl.getInv().getFuelCells(), 
							store.buyItem(Integer.parseInt(wagonTongueTextField.getText()), gameControl.getInv().getFuelCells()));
					
					store.buyItem(Integer.parseInt(wagonAxleTextField.getText()), gameControl.getInv().getHullParts(), 
							store.buyItem(Integer.parseInt(wagonAxleTextField.getText()), gameControl.getInv().getHullParts()));
					
					store.buyItem(Integer.parseInt(foodTextField.getText()), gameControl.getInv().getFood(), 
							store.buyItem(Integer.parseInt(foodTextField.getText()), gameControl.getInv().getFood()));
					
					store.buyItem(Integer.parseInt(oxenTextField.getText()), gameControl.getInv().getEngines(), 
							store.buyItem(Integer.parseInt(oxenTextField.getText()), gameControl.getInv().getEngines()));
					
					store.buyItem(Integer.parseInt(wagonWheelTextField.getText()), gameControl.getInv().getfCapacitors(), 
							store.buyItem(Integer.parseInt(wagonWheelTextField.getText()), gameControl.getInv().getfCapacitors()));
					
					store.buyItem(Integer.parseInt(clothingTextField.getText()), gameControl.getInv().getTimeSuits(), 
							store.buyItem(Integer.parseInt(clothingTextField.getText()), gameControl.getInv().getTimeSuits()));
					
					store.buyItem(Integer.parseInt(clothingTextField.getText()), gameControl.getInv().getTimeSuits(), 
							store.buyItem(Integer.parseInt(clothingTextField.getText()), gameControl.getInv().getTimeSuits()));
					
					store.buyItem(Integer.parseInt(ammunitionTextField.getText()), gameControl.getInv().getTimeBulletBills(), 
							store.buyItem(Integer.parseInt(ammunitionTextField.getText()), gameControl.getInv().getTimeBulletBills()));
				} 
				//add error message, could add it to each item, saying that if(buyItem) is false, then error
				
			}
		});
		
		nextButton3.setBounds(447, 418, 117, 29);
		inventoryPanel.add(nextButton3);
		
		backButton2 = new JButton("< Back");
		backButton2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				CardLayout cd = (CardLayout) contentPane.getLayout();
				cd.previous(contentPane);
			}
		});
		backButton2.setBounds(320, 418, 117, 29);
		inventoryPanel.add(backButton2);
	}

	@Override
	public void changedUpdate(DocumentEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void insertUpdate(DocumentEvent e) {
		if(e.getDocument().equals(oxenTextField.getDocument()))
				{
					String content=oxenTextField.getText();
					boolean checkValid=checkDataValidity(content);
					if(!checkValid){
						oxenTextField.setBackground(ERROR_COLOR);
						oxenTextFieldValidity = false;
						nextButton3.setEnabled(false);
					}
					else if(Integer.parseInt(oxenTextField.getText()) > gameControl.getInv().getEngines().getMaxAmount()){
						storeInputs[0] = Integer.parseInt(oxenTextField.getText());
						oxenTextField.setBackground(ERROR_COLOR);
						oxenTextFieldValidity = false;
						nextButton3.setEnabled(false);
					}
					else{
						storeInputs[0] = Integer.parseInt(oxenTextField.getText());
						if (canBuyFromStore()) {
							oxenTextFieldValidity = true;
							oxenTextField.setBackground(GOOD_COLOR);
							totalWeightLabel.setText("Total Weight: " + weightTotal);
							totalCostLabel.setText("Total Cost: " + storeTotal);
							if(checkTextFields()){
								nextButton3.setEnabled(true);
								
							}
						} else {
							nextButton3.setEnabled(false);
							oxenTextFieldValidity = false;
							totalWeightLabel.setText("Total Weight: " + weightTotal);
		                    totalCostLabel.setText("Total Cost: " + storeTotal);
							oxenTextField.setBackground(ERROR_COLOR);
						}
						
					}
				}
		if(e.getDocument().equals(foodTextField.getDocument()))
		{
		String content=foodTextField.getText();
		boolean checkValid=checkDataValidity(content);
		if(!checkValid){
			foodTextField.setBackground(ERROR_COLOR);
			foodTextFieldValidity = false;
			nextButton3.setEnabled(false);
		}
		else if(Integer.parseInt(foodTextField.getText()) > gameControl.getInv().getFood().getMaxAmount()){
			storeInputs[1] = Integer.parseInt(foodTextField.getText());
			foodTextField.setBackground(ERROR_COLOR);
			foodTextFieldValidity = false;
			nextButton3.setEnabled(false);
		}
		else {
			
			storeInputs[1] = Integer.parseInt(foodTextField.getText());
			if (canBuyFromStore()) {
				foodTextField.setBackground(GOOD_COLOR);
				foodTextFieldValidity = true;
				totalWeightLabel.setText("Total Weight: " + weightTotal);
				totalCostLabel.setText("Total Cost: " + storeTotal);
				if(checkTextFields()){
					nextButton3.setEnabled(true);
					
					
				}
			} else {
				nextButton3.setEnabled(false);
				foodTextFieldValidity = false;
				totalWeightLabel.setText("Total Weight: " + weightTotal);
                totalCostLabel.setText("Total Cost: " + storeTotal);
				foodTextField.setBackground(ERROR_COLOR);
			}
		}
		}
		if(e.getDocument().equals(clothingTextField.getDocument()))
		{
			String content=clothingTextField.getText();
			boolean checkValid=checkDataValidity(content);
			if(!checkValid){
				clothingTextField.setBackground(ERROR_COLOR);
				clothingTextFieldValidity = false;
				nextButton3.setEnabled(false);
			}
			else if(Integer.parseInt(clothingTextField.getText()) > gameControl.getInv().getTimeSuits().getMaxAmount()){
				storeInputs[2] = Integer.parseInt(clothingTextField.getText());
				clothingTextField.setBackground(ERROR_COLOR);
				clothingTextFieldValidity = false;
				nextButton3.setEnabled(false);
				
			}
			else {
				
				storeInputs[2] = Integer.parseInt(clothingTextField.getText());
				if (canBuyFromStore()) {
					clothingTextField.setBackground(GOOD_COLOR);
					clothingTextFieldValidity = true;
					totalWeightLabel.setText("Total Weight: " + weightTotal);
					totalCostLabel.setText("Total Cost: " + storeTotal);
					if(checkTextFields()){
						nextButton3.setEnabled(true);
						
						
					}
				} else {
					nextButton3.setEnabled(false);
					clothingTextFieldValidity = false;
					totalWeightLabel.setText("Total Weight: " + weightTotal);
                    totalCostLabel.setText("Total Cost: " + storeTotal);
					clothingTextField.setBackground(ERROR_COLOR);
				}
			}
		}
		if(e.getDocument().equals(ammunitionTextField.getDocument()))
		{
			String content=ammunitionTextField.getText();
			boolean checkValid=checkDataValidity(content);
			if(!checkValid){
				ammunitionTextField.setBackground(ERROR_COLOR);
				ammunitionTextFieldValidity = false;
				nextButton3.setEnabled(false);
				
			}
			else if(Integer.parseInt(ammunitionTextField.getText()) > gameControl.getInv().getTimeBulletBills().getMaxAmount()){
				storeInputs[3] = Integer.parseInt(ammunitionTextField.getText());
				ammunitionTextField.setBackground(ERROR_COLOR);
				ammunitionTextFieldValidity = false;
				nextButton3.setEnabled(false);
				
			}
			else {
				
				storeInputs[3] = Integer.parseInt(ammunitionTextField.getText());
				if (canBuyFromStore()) {
					ammunitionTextField.setBackground(GOOD_COLOR);
					ammunitionTextFieldValidity = true;
					totalWeightLabel.setText("Total Weight: " + weightTotal);
					totalCostLabel.setText("Total Cost: " + storeTotal);
					if(checkTextFields()){
					nextButton3.setEnabled(true);
					
					
					}
				} else {
					nextButton3.setEnabled(false);
					ammunitionTextFieldValidity = false;
					totalWeightLabel.setText("Total Weight: " + weightTotal);
                    totalCostLabel.setText("Total Cost: " + storeTotal);
					ammunitionTextField.setBackground(ERROR_COLOR);
				}
			}
		}
		if(e.getDocument().equals(wagonWheelTextField.getDocument()))
		{
			String content=wagonWheelTextField.getText();
			boolean checkValid=checkDataValidity(content);
			if(!checkValid){
				wagonWheelTextField.setBackground(ERROR_COLOR);
				wagonWheelTextFieldValidity = false;
				nextButton3.setEnabled(false);
			}
			else if(Integer.parseInt(wagonWheelTextField.getText()) > gameControl.getInv().getfCapacitors().getMaxAmount()){
				storeInputs[4] = Integer.parseInt(wagonWheelTextField.getText());
				wagonWheelTextField.setBackground(ERROR_COLOR);
				wagonWheelTextFieldValidity = false;
				nextButton3.setEnabled(false);
				
			}
			else {
				
				storeInputs[4] = Integer.parseInt(wagonWheelTextField.getText());
				if (canBuyFromStore()) {
					wagonWheelTextField.setBackground(GOOD_COLOR);
					wagonWheelTextFieldValidity = true;
					totalWeightLabel.setText("Total Weight: " + weightTotal);
					totalCostLabel.setText("Total Cost: " + storeTotal);
					if(checkTextFields()){
					nextButton3.setEnabled(true);
					
					
					}
				} else {
					nextButton3.setEnabled(false);
					wagonWheelTextFieldValidity = false;
					totalWeightLabel.setText("Total Weight: " + weightTotal);
                    totalCostLabel.setText("Total Cost: " + storeTotal);
					wagonWheelTextField.setBackground(ERROR_COLOR);
					
				}
			}
		}
		if(e.getDocument().equals(wagonAxleTextField.getDocument()))
		{
			String content=wagonAxleTextField.getText();
			boolean checkValid=checkDataValidity(content);
			if(!checkValid){
				nextButton3.setEnabled(false);
				wagonAxleTextFieldValidity = false;
				wagonAxleTextField.setBackground(ERROR_COLOR);
			}
			else if(Integer.parseInt(wagonAxleTextField.getText()) > gameControl.getInv().getHullParts().getMaxAmount()){
				storeInputs[5] = Integer.parseInt(wagonAxleTextField.getText());
				wagonAxleTextField.setBackground(ERROR_COLOR);
				wagonAxleTextFieldValidity = false;
				nextButton3.setEnabled(false);
				
			}
			else {
				
				storeInputs[5] = Integer.parseInt(wagonAxleTextField.getText());
				if (canBuyFromStore()) {
					wagonAxleTextField.setBackground(GOOD_COLOR);
					wagonAxleTextFieldValidity = true;
					totalWeightLabel.setText("Total Weight: " + weightTotal);
					totalCostLabel.setText("Total Cost: " + storeTotal);
					if(checkTextFields()){
					nextButton3.setEnabled(true);
					
					
					}
				} else {
					nextButton3.setEnabled(false);
					wagonAxleTextFieldValidity = false;
					totalWeightLabel.setText("Total Weight: " + weightTotal);
                    totalCostLabel.setText("Total Cost: " + storeTotal);
					wagonAxleTextField.setBackground(ERROR_COLOR);
				}
			}
		}
		
		if(e.getDocument().equals(wagonTongueTextField.getDocument()))
		{
			
					String content=wagonTongueTextField.getText();
					boolean checkValid=checkDataValidity(content);
					if(!checkValid){
						nextButton3.setEnabled(false);
						wagonTongueTextFieldValidity = false;
						wagonTongueTextField.setBackground(ERROR_COLOR);
					}
					else if(Integer.parseInt(wagonTongueTextField.getText()) > gameControl.getInv().getFuelCells().getMaxAmount()){
						storeInputs[6] = Integer.parseInt(wagonTongueTextField.getText());
						wagonTongueTextField.setBackground(ERROR_COLOR);
						wagonTongueTextFieldValidity = false;
						nextButton3.setEnabled(false);
					}
					else {
						storeInputs[6] = Integer.parseInt(wagonTongueTextField.getText());
						if (canBuyFromStore()) {
							wagonTongueTextField.setBackground(GOOD_COLOR);
							wagonTongueTextFieldValidity = true;
							totalWeightLabel.setText("Total Weight: " + weightTotal);
							totalCostLabel.setText("Total Cost: " + storeTotal);
							if(checkTextFields()){
							nextButton3.setEnabled(true);
							
							
							}
						} else {
							nextButton3.setEnabled(false);
							wagonTongueTextFieldValidity = false;
							totalWeightLabel.setText("Total Weight: " + weightTotal);
		                    totalCostLabel.setText("Total Cost: " + storeTotal);
							wagonTongueTextField.setBackground(ERROR_COLOR);
						} 
					}
		
		}
			}
	@Override
	public void removeUpdate(DocumentEvent e) {
		if(e.getDocument().equals(oxenTextField.getDocument()))
		{
			String content=oxenTextField.getText();
			boolean checkValid=checkDataValidity(content);
			if(!checkValid){
				oxenTextField.setBackground(ERROR_COLOR);
				oxenTextFieldValidity = false;
				nextButton3.setEnabled(false);
			}
			else if(Integer.parseInt(oxenTextField.getText()) > gameControl.getInv().getEngines().getMaxAmount()){
				storeInputs[0] = Integer.parseInt(oxenTextField.getText());
				oxenTextField.setBackground(ERROR_COLOR);
				oxenTextFieldValidity = false;
				nextButton3.setEnabled(false);
			}
			else{
				storeInputs[0] = Integer.parseInt(oxenTextField.getText());
				if (canBuyFromStore()) {
					oxenTextFieldValidity = true;
					oxenTextField.setBackground(GOOD_COLOR);
					totalWeightLabel.setText("Total Weight: " + weightTotal);
					totalCostLabel.setText("Total Cost: " + storeTotal);
					if(checkTextFields()){
						nextButton3.setEnabled(true);
						
					}
				} else {
					nextButton3.setEnabled(false);
					oxenTextFieldValidity = false;
					totalWeightLabel.setText("Total Weight: " + weightTotal);
                    totalCostLabel.setText("Total Cost: " + storeTotal);
					oxenTextField.setBackground(ERROR_COLOR);
				}
				
			}
		}
if(e.getDocument().equals(foodTextField.getDocument()))
{
String content=foodTextField.getText();
boolean checkValid=checkDataValidity(content);
if(!checkValid){
	foodTextField.setBackground(ERROR_COLOR);
	foodTextFieldValidity = false;
	nextButton3.setEnabled(false);
}
else if(Integer.parseInt(foodTextField.getText()) > gameControl.getInv().getFood().getMaxAmount()){
	storeInputs[1] = Integer.parseInt(foodTextField.getText());
	foodTextField.setBackground(ERROR_COLOR);
	foodTextFieldValidity = false;
	nextButton3.setEnabled(false);
}
else {
	
	storeInputs[1] = Integer.parseInt(foodTextField.getText());
	if (canBuyFromStore()) {
		foodTextField.setBackground(GOOD_COLOR);
		foodTextFieldValidity = true;
		totalWeightLabel.setText("Total Weight: " + weightTotal);
		totalCostLabel.setText("Total Cost: " + storeTotal);
		if(checkTextFields()){
			nextButton3.setEnabled(true);
			
			
		}
	} else {
		nextButton3.setEnabled(false);
		foodTextFieldValidity = false;
		totalWeightLabel.setText("Total Weight: " + weightTotal);
        totalCostLabel.setText("Total Cost: " + storeTotal);
		foodTextField.setBackground(ERROR_COLOR);
	}
}
}
if(e.getDocument().equals(clothingTextField.getDocument()))
{
	String content=clothingTextField.getText();
	boolean checkValid=checkDataValidity(content);
	if(!checkValid){
		clothingTextField.setBackground(ERROR_COLOR);
		clothingTextFieldValidity = false;
		nextButton3.setEnabled(false);
	}
	else if(Integer.parseInt(clothingTextField.getText()) > gameControl.getInv().getTimeSuits().getMaxAmount()){
		storeInputs[2] = Integer.parseInt(clothingTextField.getText());
		clothingTextField.setBackground(ERROR_COLOR);
		clothingTextFieldValidity = false;
		nextButton3.setEnabled(false);
		
	}
	else {
		
		storeInputs[2] = Integer.parseInt(clothingTextField.getText());
		if (canBuyFromStore()) {
			clothingTextField.setBackground(GOOD_COLOR);
			clothingTextFieldValidity = true;
			totalWeightLabel.setText("Total Weight: " + weightTotal);
			totalCostLabel.setText("Total Cost: " + storeTotal);
			if(checkTextFields()){
				nextButton3.setEnabled(true);
				
				
			}
		} else {
			nextButton3.setEnabled(false);
			clothingTextFieldValidity = false;
			totalWeightLabel.setText("Total Weight: " + weightTotal);
            totalCostLabel.setText("Total Cost: " + storeTotal);
			clothingTextField.setBackground(ERROR_COLOR);
		}
	}
}
if(e.getDocument().equals(ammunitionTextField.getDocument()))
{
	String content=ammunitionTextField.getText();
	boolean checkValid=checkDataValidity(content);
	if(!checkValid){
		ammunitionTextField.setBackground(ERROR_COLOR);
		ammunitionTextFieldValidity = false;
		nextButton3.setEnabled(false);
		
	}
	else if(Integer.parseInt(ammunitionTextField.getText()) > gameControl.getInv().getTimeBulletBills().getMaxAmount()){
		storeInputs[3] = Integer.parseInt(ammunitionTextField.getText());
		ammunitionTextField.setBackground(ERROR_COLOR);
		ammunitionTextFieldValidity = false;
		nextButton3.setEnabled(false);
		
	}
	else {
		
		storeInputs[3] = Integer.parseInt(ammunitionTextField.getText());
		if (canBuyFromStore()) {
			ammunitionTextField.setBackground(GOOD_COLOR);
			ammunitionTextFieldValidity = true;
			totalWeightLabel.setText("Total Weight: " + weightTotal);
			totalCostLabel.setText("Total Cost: " + storeTotal);
			if(checkTextFields()){
			nextButton3.setEnabled(true);
			
			
			}
		} else {
			nextButton3.setEnabled(false);
			ammunitionTextFieldValidity = false;
			totalWeightLabel.setText("Total Weight: " + weightTotal);
            totalCostLabel.setText("Total Cost: " + storeTotal);
			ammunitionTextField.setBackground(ERROR_COLOR);
		}
	}
}
if(e.getDocument().equals(wagonWheelTextField.getDocument()))
{
	String content=wagonWheelTextField.getText();
	boolean checkValid=checkDataValidity(content);
	if(!checkValid){
		wagonWheelTextField.setBackground(ERROR_COLOR);
		wagonWheelTextFieldValidity = false;
		nextButton3.setEnabled(false);
	}
	else if(Integer.parseInt(wagonWheelTextField.getText()) > gameControl.getInv().getfCapacitors().getMaxAmount()){
		storeInputs[4] = Integer.parseInt(wagonWheelTextField.getText());
		wagonWheelTextField.setBackground(ERROR_COLOR);
		wagonWheelTextFieldValidity = false;
		nextButton3.setEnabled(false);
		
	}
	else {
		
		storeInputs[4] = Integer.parseInt(wagonWheelTextField.getText());
		if (canBuyFromStore()) {
			wagonWheelTextField.setBackground(GOOD_COLOR);
			wagonWheelTextFieldValidity = true;
			totalWeightLabel.setText("Total Weight: " + weightTotal);
			totalCostLabel.setText("Total Cost: " + storeTotal);
			if(checkTextFields()){
			nextButton3.setEnabled(true);
			
			
			}
		} else {
			nextButton3.setEnabled(false);
			wagonWheelTextFieldValidity = false;
			totalWeightLabel.setText("Total Weight: " + weightTotal);
            totalCostLabel.setText("Total Cost: " + storeTotal);
			wagonWheelTextField.setBackground(ERROR_COLOR);
		}
	}
}
if(e.getDocument().equals(wagonAxleTextField.getDocument()))
{
	String content=wagonAxleTextField.getText();
	boolean checkValid=checkDataValidity(content);
	if(!checkValid){
		nextButton3.setEnabled(false);
		wagonAxleTextFieldValidity = false;
		wagonAxleTextField.setBackground(ERROR_COLOR);
	}
	else if(Integer.parseInt(wagonAxleTextField.getText()) > gameControl.getInv().getHullParts().getMaxAmount()){
		storeInputs[5] = Integer.parseInt(wagonAxleTextField.getText());
		wagonAxleTextField.setBackground(ERROR_COLOR);
		wagonAxleTextFieldValidity = false;
		nextButton3.setEnabled(false);
		
	}
	else {
		
		storeInputs[5] = Integer.parseInt(wagonAxleTextField.getText());
		if (canBuyFromStore()) {
			wagonAxleTextField.setBackground(GOOD_COLOR);
			wagonAxleTextFieldValidity = true;
			totalWeightLabel.setText("Total Weight: " + weightTotal);
			totalCostLabel.setText("Total Cost: " + storeTotal);
			if(checkTextFields()){
			nextButton3.setEnabled(true);
			
			
			}
		} else {
			nextButton3.setEnabled(false);
			wagonAxleTextFieldValidity = false;
			totalWeightLabel.setText("Total Weight: " + weightTotal);
            totalCostLabel.setText("Total Cost: " + storeTotal);
			wagonAxleTextField.setBackground(ERROR_COLOR);
		}
	}
}

if(e.getDocument().equals(wagonTongueTextField.getDocument()))
{
	
			String content=wagonTongueTextField.getText();
			boolean checkValid=checkDataValidity(content);
			if(!checkValid){
				nextButton3.setEnabled(false);
				wagonTongueTextFieldValidity = false;
				wagonTongueTextField.setBackground(ERROR_COLOR);
			}
			else if(Integer.parseInt(wagonTongueTextField.getText()) > gameControl.getInv().getFuelCells().getMaxAmount()){
				storeInputs[6] = Integer.parseInt(wagonTongueTextField.getText());
				wagonTongueTextField.setBackground(ERROR_COLOR);
				wagonTongueTextFieldValidity = false;
				nextButton3.setEnabled(false);
			}
			else {
				storeInputs[6] = Integer.parseInt(wagonTongueTextField.getText());
				if (canBuyFromStore()) {
					wagonTongueTextField.setBackground(GOOD_COLOR);
					wagonTongueTextFieldValidity = true;
					totalWeightLabel.setText("Total Weight: " + weightTotal);
					totalCostLabel.setText("Total Cost: " + storeTotal);
					
					if(checkTextFields()){
					nextButton3.setEnabled(true);
					
					
					}
				} else {
					nextButton3.setEnabled(false);
					wagonTongueTextFieldValidity = false;
					totalWeightLabel.setText("Total Weight: " + weightTotal);
                    totalCostLabel.setText("Total Cost: " + storeTotal);
					wagonTongueTextField.setBackground(ERROR_COLOR);
				} 
			}

}
	}
	
}
